dnl Copyright (c) 2009-2010, Sean A.O. Harney <sharney3@gmail.com>
dnl Process this file with autoconf to produce a configure script.

define([svnversion], esyscmd([sh -c "svnversion|tr -d '\n'"]))
AC_INIT([omf], [0.1.svnversion])
AC_CONFIG_SRCDIR([src/main.c])

dnl foreign is least strict
AM_INIT_AUTOMAKE([foreign])

AC_CANONICAL_HOST
AC_MSG_CHECKING([for supported operating system])
case "$host_os" in
linux*)                 AC_DEFINE([OS_LINUX]) ;;
*)                      AC_MSG_RESULT([NO!])
                        AC_MSG_ERROR([unsupported operating system: $host_os !!!]) ;;
esac
AC_MSG_RESULT($host_os)

AC_MSG_CHECKING([for supported architecture])
case "$host_cpu" in
i[[3456]]86|pentium)    AC_DEFINE([ARCH_X86]) ;;
x86_64)			AC_DEFINE([ARCH_X86_64]) ;;
*)                      AC_MSG_RESULT([NO!])
                        AC_MSG_ERROR([unsupported architecture: $host_cpu !!!]) ;;
esac

AC_MSG_RESULT($host_cpu)
# Checks for programs.
AC_PROG_CC
AC_PROG_YACC
AM_PROG_LEX
#AM_PROG_LEX recommended over AC_PROG_LEX


# Checks for header files.
AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.h malloc.h stddef.h zip.h])
AC_HEADER_STDBOOL

# Checks for libraries.
# FIXME: Replace `main' with a function in `-lm':
#AC_CHECK_LIB([m], [main])
AC_CHECK_LIB([m], [cos])
AC_CHECK_LIB([crypt], [crypt])
#AC_CHECK_LIB([ssl], [SSL_accept])
#AC_CHECK_LIB([ffi], [ffi_call])
AC_CHECK_LIB([zip], [zip_open])

PKG_CHECK_MODULES([FFI], [libffi], [LIBFFI_FOUND=yes], [LIBFFI_FOUND=no])
if test "x${LIBFFI_FOUND}" = xno
then
  LIBFFI_FOUND=
  AC_CHECK_HEADER([ffi.h],[LIBFFI_CFLAGS=],[LIBFFI_FOUND=no])
  AC_SEARCH_LIBS([ffi_call], [ffi],[LIBFFI_LIBS=-lffi],[LIBFFI_FOUND=no])
  if test "x${LIBFFI_FOUND}" = xno
    then
      AC_MSG_ERROR([Could not find libffi headers - \
      Instal libffi-devel or libffi-dev.])
 fi
fi
AC_SUBST(LIBFFI_CFLAGS)
AC_SUBST(LIBFFI_LIBS)

# centos x86_64 doesn't have it.
m4_pattern_allow([^AC_TYPE_UINT8_T$]) 
# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_UINT8_T

# Checks for library functions.
AC_FUNC_ALLOCA
AC_CHECK_FUNCS([strsignal dup2 strtol setpgid getpgid zip_open])

AC_CONFIG_FILES([Makefile src/Makefile test-omf-scripts/Makefile docs/Makefile man/Makefile])
AC_OUTPUT
